//package com.ruoyi.uniapp.unilogin.service.impl;
//
//import com.ruoyi.uniapp.unilogin.domain.UniUser;
//import com.ruoyi.uniapp.unilogin.mapper.UniUserMapper;
//import com.ruoyi.uniapp.unilogin.service.UniUserService;
//import io.jsonwebtoken.Jwts;
//import io.jsonwebtoken.SignatureAlgorithm;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//
//import java.util.Date;
//import java.util.HashMap;
//import java.util.Map;
//
//@Service
//public class UniUserServiceImpl implements UniUserService {
//    @Autowired
//    private UniUserMapper uniUserMapper;
//
//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public String login(String username, String password) {
//        QueryWrapper<UniUser> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("username", username);
//        UniUser uniUser = uniUserMapper.selectOne(queryWrapper);
//        if (uniUser != null && uniUser.getPassword().equals(password)) {
//            // 生成JWT token
//            long nowMillis = System.currentTimeMillis();
//            Date now = new Date(nowMillis);
//            long expMillis = nowMillis + 3600000; // 设置token有效期为1小时
//            Date exp = new Date(expMillis);
//            Map<String, Object> claims = new HashMap<>();
//            claims.put("username", username);
//            String token = Jwts.builder()
//                    .setClaims(claims)
//                    .setIssuedAt(now)
//                    .setExpiration(exp)
//                    .signWith(SignatureAlgorithm.HS256, "secret") // 使用HS256算法和密钥签名
//                    .compact();
//            return token;
//        } else {
//            throw new RuntimeException("用户名或密码错误");
//        }
//    }
//}